package com.esri.core.geodatabase;

import com.esri.core.internal.util.d;
import java.util.ArrayList;
import java.util.List;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class Relationship {
    int a;
    String b;
    String c;
    Cardinality d;
    Role e;
    boolean f;
    private int g;
    private Geodatabase h;
    private GeodatabaseFeatureTable i;

    /* loaded from: classes.dex */
    public enum Cardinality {
        ONE_TO_ONE("esriRelCardinalityOneToOne"),
        ONE_TO_MANY("esriRelCardinalityOneToMany"),
        MANY_TO_MANY("esriRelCardinalityManyToMany");
        
        String a;

        Cardinality(String str) {
            this.a = str;
        }

        public String getValue() {
            return this.a;
        }

        @Override // java.lang.Enum
        public String toString() {
            return super.toString() + "(" + this.a + ")";
        }

        public static Cardinality get(String str) {
            Cardinality[] values;
            for (Cardinality cardinality : values()) {
                if (cardinality.a.equals(str)) {
                    return cardinality;
                }
            }
            return null;
        }
    }

    /* loaded from: classes.dex */
    public enum Role {
        ORIGIN("esriRelRoleOrigin"),
        DESTINATION("esriRelRoleDestination");
        
        String a;

        Role(String str) {
            this.a = str;
        }

        public String getValue() {
            return this.a;
        }

        @Override // java.lang.Enum
        public String toString() {
            return super.toString() + "(" + this.a + ")";
        }

        public static Role get(String str) {
            Role[] values;
            for (Role role : values()) {
                if (role.a.equals(str)) {
                    return role;
                }
            }
            return null;
        }
    }

    public int getId() {
        return this.a;
    }

    public String getName() {
        return this.b;
    }

    public String getKeyField() {
        return this.c;
    }

    public Cardinality getCardinality() {
        return this.d;
    }

    public Role getRole() {
        return this.e;
    }

    public boolean isComposite() {
        return this.f;
    }

    public GeodatabaseFeatureTable getRelatedTable() {
        GeodatabaseFeatureTable geodatabaseFeatureTable = this.i;
        if (geodatabaseFeatureTable != null) {
            return geodatabaseFeatureTable;
        }
        for (GeodatabaseFeatureTable geodatabaseFeatureTable2 : this.h.getGeodatabaseTables()) {
            if (geodatabaseFeatureTable2.getLayerServiceInfo().getId() == this.g) {
                return geodatabaseFeatureTable2;
            }
        }
        return null;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public int a() {
        return this.g;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void a(GeodatabaseFeatureTable geodatabaseFeatureTable) {
        this.i = geodatabaseFeatureTable;
    }

    public static List<Relationship> listFromJson(JsonParser jsonParser, Geodatabase geodatabase) throws Exception {
        if (geodatabase == null) {
            throw new RuntimeException("Geodatabase can't be null.");
        }
        ArrayList arrayList = new ArrayList();
        if (d.c(jsonParser)) {
            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                String currentName = jsonParser.getCurrentName();
                jsonParser.nextToken();
                if ("relationships".equals(currentName)) {
                    if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                        while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                            arrayList.add(fromJson(jsonParser, geodatabase));
                        }
                    }
                } else {
                    jsonParser.skipChildren();
                }
            }
            return arrayList;
        }
        return null;
    }

    public static Relationship fromJson(JsonParser jsonParser, Geodatabase geodatabase) throws Exception {
        if (!d.c(jsonParser)) {
            throw new RuntimeException("Illegal format for relationships.");
        }
        Relationship relationship = new Relationship();
        relationship.h = geodatabase;
        while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
            String currentName = jsonParser.getCurrentName();
            jsonParser.nextToken();
            if ("id".equals(currentName)) {
                relationship.a = jsonParser.getIntValue();
            } else if ("name".equals(currentName)) {
                relationship.b = jsonParser.getText();
            } else if ("relatedTableId".equals(currentName)) {
                relationship.g = jsonParser.getIntValue();
            } else if ("cardinality".equals(currentName)) {
                relationship.d = Cardinality.get(jsonParser.getText());
            } else if ("role".equals(currentName)) {
                relationship.e = Role.get(jsonParser.getText());
            } else if ("keyField".equals(currentName)) {
                relationship.c = jsonParser.getText();
            } else if ("composite".equals(currentName)) {
                relationship.f = jsonParser.getBooleanValue();
            } else {
                jsonParser.skipChildren();
            }
        }
        return relationship;
    }

    public String toString() {
        return "Relationship [id=" + this.a + ", name=" + this.b + "]";
    }
}
